<template>
  <div id="app">
    <h2>测试题</h2>
    <SubjectItem v-for="(item, index) in subjectItems" :key="index" @answer-submitted="handleAnswerSubmitted(index, $event)"></SubjectItem>
    <div>
      <FlagItem v-for="(result, index) in results" :key="index" :result="result" :index="index"></FlagItem>
    </div>
  </div>
</template>

<script>
import SubjectItem from './components/SubjectItem.vue';
import FlagItem from './components/FlagItem.vue';

export default {
  components: {
    SubjectItem,
    FlagItem
  },
  data() {
    return {
      subjectItems: Array.from({ length: 5 }).map(() => ({})), // 初始化题目列表，可根据需求调整数量
      results: Array.from({ length: 5 }).map(() => ({ userAnswer: null, correctAnswer: null, isAnswered: false }))
    };
  },
  methods: {
    handleAnswerSubmitted(index, { userAnswer, correctAnswer }) {
      const result = { userAnswer, correctAnswer, isAnswered: true };
      this.$set(this.results, index, result);
    }
  }
};
</script>

<style>
body {
  background-color: #eee;
}

#app {
  background-color: #fff;
  width: 500px;
  margin: 50px auto;
  box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);
  padding: 2em;
}
</style>